<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start(); //we need to call PHP's session object to access it through CI
class Housing extends CI_Controller {

 function __construct() {
   parent::__construct();
   $this->load->model('housing_model','',TRUE);
 }

 //Loads the users view
 function index() {
   if($this->session->userdata('logged_in')) {
     $session_data = $this->session->userdata('logged_in');
     $data['ds_usuario'] = $session_data['ds_usuario'];
     $this->load->view('housing_view', $data);
   } else {
     redirect('login', 'refresh');
   }
 }

function savehouse() {
  if($this->input->post("housenum") && $this->input->post("detail")){
      $houseid = $this->input->post('houseid'); 
      $housenum = $this->input->post('housenum');
      $detail = $this->input->post('detail');
      $housedorp = $this->input->post('housedorp');
      //query the database
      $result = $this->housing_model->save($houseid, $housenum, $detail, $housedorp);
      if($result) {
        echo json_encode(array("response" => "success"));
      } else {
        echo json_encode(array("response" => "failed"));
      }
  } else {
      echo json_encode(array("response" => "incomplete_form"));
  }

 }

 function returnhousesbydorp($id) {
   //query the database
   $result = $this->housing_model->gethousesbydorp($id);
   if($result) {
     echo json_encode($result);
   }
 }

 function returnhousebyid($id) {
   //query the database
   $result = $this->housing_model->gethousebyid($id);
   if($result) {
     echo json_encode($result);
   }
 }

}

?>